package com.wman.mvp.base

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.wman.mvp.mvp.presenter.BasePresenter

abstract class BaseActivity<V, P : BasePresenter<V>> : AppCompatActivity() {
    private var mPresenter: P? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContentView(getLayoutId())

        if (mPresenter == null) {
            mPresenter = createPresenter() as P
        }
        mPresenter!!.bindView(this as V)

        init()

        initData()
    }

    protected abstract fun getLayoutId(): Int

    protected abstract fun createPresenter(): P

    protected abstract fun init()

    protected abstract fun initData()

    protected fun getPresenter() = mPresenter

    override fun onDestroy() {
        super.onDestroy()
        this.mPresenter!!.unBindView()
    }
}
